package com.itcase.controller;

import com.itcase.domain.User;
import com.itcase.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/findAllUserInfo")
    public String findAllUserInfo(HttpSession session) {
        List<User> userList =userService.findAllUserInfo();
        session.setAttribute("list",userList);
        return "/User_List";
    }

    @RequestMapping("/updateUser")
    public String updateUser(User user) {
       userService.updateUser(user);
        return "redirect:findAllUserInfo";
    }

    @RequestMapping("/addUser")
    public String addUser(User user) {
        userService.addUser(user);

        return "redirect:findAllUserInfo";
    }
    @RequestMapping("/deleteUser")
    public String deleteUser(String id) {
        userService.deleteUser(id);

        return "redirect:findAllUserInfo";
    }
    @RequestMapping("/findUserById")
    public String findUserById(String id,HttpSession session) {
        User user =userService.findUserById(id);
        session.setAttribute("user",user);
        return "/User_Update";
    }

}
